import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    publicKey :"",
    currentItem: null,
    renameItem:null,//重名命选项的数据
    currentEditArt:null, //当钱编辑对象
    currentViewpost: null, //当前查看文章对象
    currentIndex: null,
    noteBooke:{
      path: []
    },
    rm:{
      dirItem:null,
      file: null
    },
    pageInfo:{
      total: 0, //总共几条数据
      len: 0
    },
    userInfo: null
  },
  getters:{
    //获取用户信息
    getUserInfo( state ){
      return state.userInfo;
    },
    //获取分页配置信息
    getPageInfo( state ){
      return state.pageInfo;
    },
    //获取公钥
    getPublicKey( state ){
      return state.publicKey;
    },
    getCurrentItem( state ){
      return state.currentItem;
    },
    getRmDir( state ){
      return state.rm.dirItem;
    },
    getPathOfNotebook( state ){
      return state.noteBooke.path;
    },
    getEndOfPathOfNotebookItem(state){
      let path = state.noteBooke.path;
      return path[path.length - 1];
    },
    //获取将重命名数据的内容
    getRenameOption( state ){
      return state.renameItem;
    },
    //获取但当前编辑的文章参数
    getCurrentEditArticle( state ){
      return state.currentEditArt;
    },
    //获取当前查看文章对象
    getcurrentViewpost( state ){
      return state.currentViewpost;
    },
    //获取当前选中文章下标
    getcurrentIndex( state ){
      return state.currentIndex;
    }
  },
  mutations: {
    //设置用户信息
    setUserInfo( state , info ){
      state.userInfo = info;
    },
    //设置分页配置信息
    setPageInfo( state , pageArgs ){
      // pageInfo:{
      //   pageSize: 18, //每页18条数据
      //   currentPage: 0, //当前第一页
      //   total: 0, //总共几条数据
      //   len: 0
      // }
      state.pageInfo = pageArgs;
    },
    //设置将要重命名的数据内容
    setRenameObjectOption( state , item ){
      state.renameItem = item;
    },
    setPublicKey( state , val){
      state.publicKey = val;
    },
    setCurrentItem( state, item ){
      state.currentItem = item;
    },
    setRmItem( state , item ){
      state.rm.dirItem = item;
    },
    resetRmItem( state ){
      state.rm.dirItem = null;
    },
    setMenuPath( state , item ){
      let menuPath =  state.noteBooke.path;
      if(item.top_id){
        menuPath.length = 0;
        menuPath.push(item);
        return ;
      }
      menuPath.push(item);
    },
    feetBackMenuPath( state ){
      
      let menuPath = state.noteBooke.path;
      if( menuPath.length > 1 ){
        menuPath.splice( menuPath.length - 1 , 1);
      }
      //设置当前目录
      this.commit('setCurrentItem', menuPath[ menuPath.length - 1 ]);
      
    },
    //设置当前编辑文章的参数
    setCurrentEditArticle( state , item ){
      state.currentEditArt = item;
    },
    //设置当前查看文章对象
    setcurrentViewpost( state , item ){
      console.log("vuex item: ", item);
      state.currentViewpost = item.constent;
      if( item.index ){
        state.currentIndex = item.index;
      }
    }
  },
  actions: {
  },
  modules: {
  }
})
